package com.cy.ppj.service.dealrecord.impl;

import com.cy.ppj.dao.mapper.account.DealRecordMapper;
import com.cy.ppj.model.PageBean;
import com.cy.ppj.model.domian.account.DealRecord;
import com.cy.ppj.model.query.DealRecordAdminQuery;
import com.cy.ppj.model.query.dealrecord.DealRecordQuery;
import com.cy.ppj.model.vo.admin.dealrecord.DealRecordAdminVO;
import com.cy.ppj.model.vo.front.dealrecord.DealRecordVO;
import com.cy.ppj.service.BaseService;
import com.cy.ppj.service.dealrecord.DealRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 交易记录
 * @author: Ocean
 * @create: 2018-09-04 14:38
 **/
@Slf4j
@Service
public class DealRecordServiceImpl extends BaseService implements DealRecordService {

    @Autowired
    private DealRecordMapper dealRecordMapper;

    @Override
    public PageBean<DealRecordVO> queryDealRecord(DealRecordQuery query) {

        List<DealRecordVO> list = new ArrayList<>();
        int tolal = dealRecordMapper.selectDealRecordCount(query);
        if (tolal > 0) {
            query.startPage();
            list = dealRecordMapper.selectDealRecordList(query);
            list.stream().forEach(d -> {
                d.setTypeText(d.getType().getText());
                switch (d.getType().getType()) {
                    case ADD_USABLE:
                    case FREEZE_TO_USABLE:
                        d.setSymbol("+");
                        break;

                    case SUB_USABLE:
                    case SUB_FREEZE:
                    case USABLE_TO_FREEZE:
                        d.setSymbol("-");
                        break;

                    default:
                        break;
                }
            });
        }

        return new PageBean<>(list, tolal);
    }

    @Override
    public PageBean<DealRecordAdminVO> queryDealRecordAdmin(DealRecordAdminQuery query) {
        int total = dealRecordMapper.queryDealRecordsByUserIdCount(query);
        List<DealRecordAdminVO> list = new ArrayList<>();
        if (total > 0) {
        	query.startPage();
            list = dealRecordMapper.queryDealRecordsByUserId(query);
            list.stream().forEach(d -> {
                d.setTypeText(d.getType().getText());
            });
        }
        return new PageBean<>(list, total);
    }
}
